package com.sky.controller.admin;

import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController("adminShop")
@RequestMapping("/admin/shop")
@Api(tags = "服务端状态")
public class ShopController {
    @Autowired
    private RedisTemplate redisTemplate;
    private final String KEY = "STOP_STATUS";

    @ApiOperation("更改服务端状态的功能")
    @PutMapping("/{status}")
    public Result setStatus(@PathVariable Integer status) {

        log.info("正在执行更改服务端的状态功能........状态为:{}", status);

        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set(KEY, status);
        return Result.success();
    }

    @ApiOperation("获取服务端状态的功能")
    @GetMapping("/status")
    public Result getStatus() {
        log.info("正在执行获取服务端的状态功能........");
        ValueOperations valueOperations = redisTemplate.opsForValue();
        Object value = valueOperations.get(KEY);
        return Result.success(value);

    }

}